<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text" encoding="iso-8859-1" />

<xsl:template match="/">
      <xsl:variable name="uaj" select="//PARAMETRES/UAJ"/>
      <xsl:variable name="annee" select="//PARAMETRES/ANNEE_SCOLAIRE"/>
      
      <!-- ELEVES 
      <xsl:for-each select="//ELEVES/ELEVE">
        <xsl:variable name="sortie" select="DATE_SORTIE" />
INSERT INTO uni_eleve (baseid, nom, prenom, ine, id_siecle)
VALUES(1,
       '<xsl:value-of select="NOM" />',
       '<xsl:value-of select="PRENOM" />',
       '<xsl:value-of select="ID_NATIONAL" />',
       '<xsl:value-of select="@ELEVE_ID" />');$$
       
INSERT INTO uni_scolarite_eleve (eleveid, structureid, mefid, debut, fin, actuelle)
VALUES(LAST_INSERT_ID(),
       210,
       <xsl:choose>
           <xsl:when test="CODE_MEF">
               getMefByCodeSiecle(1, '<xsl:value-of select="CODE_MEF" />'),
           </xsl:when>
           <xsl:otherwise>
               227,
           </xsl:otherwise>
        </xsl:choose>
       NOW(),
       NULL,
       1);$$
       
       
      </xsl:for-each>
     -->
     
     <!-- ELEVES MEFS -->
     <!--
     <xsl:for-each select="//ELEVES/ELEVE">
         <xsl:if test="CODE_MEF">
UPDATE uni_scolarite_eleve SET mefid=getMefByCodeSiecle(1, '<xsl:value-of select="CODE_MEF" />') WHERE eleveid=getEleveIdByIdSiecle(1, '<xsl:value-of select="@ELEVE_ID" />');$$
         </xsl:if>
     </xsl:for-each>
     -->
      <!--ELEVES STRUCTURES -->
      <!--
      <xsl:for-each select="//STRUCTURES/STRUCTURES_ELEVE">
          
          <xsl:choose>
              <xsl:when test="STRUCTURE/TYPE_STRUCTURE='D'">
UPDATE uni_scolarite_eleve SET structureid=getStructureIdByIdSiecle(1, '<xsl:value-of select="STRUCTURE/CODE_STRUCTURE" />') WHERE eleveid=getEleveIdByIdSiecle(1, '<xsl:value-of select="@ELEVE_ID" />');
              </xsl:when>
              <xsl:otherwise>
INSERT INTO uni_eleve_structure (baseid, eleveid, structureid, debut, fin)
VALUES(1, 
       getEleveIdByIdSiecle(1, '<xsl:value-of select="@ELEVE_ID" />'),
       getStructureIdByIdSiecle(1, '<xsl:value-of select="STRUCTURE/CODE_STRUCTURE" />'),
       NOW(),
       NULL);           
              </xsl:otherwise>
          </xsl:choose>
      </xsl:for-each>
      -->
      <!--
       ELEVES OPTIONS
       
       -->
      <xsl:for-each select="//OPTIONS/OPTION/OPTIONS_ELEVE">
INSERT INTO uni_option_eleve (scolariteid, matiereid, modalite, debut, fin) 
VALUES(getScolariteIdByEleveSiecle(1, '<xsl:value-of select="../@ELEVE_ID" />'),
       getMatiereIdByIdSiecle(1, '<xsl:value-of select="CODE_MATIERE" />'),       
       '<xsl:value-of select="CODE_MODALITE_ELECT" />',
       NOW(),
       NULL
);     
      </xsl:for-each>
 </xsl:template>

</xsl:stylesheet>